#!/bin/bash
#
# USAGE:
# 	giant step
#
# DESCRIPTION:
#  GIANT is an ADORE function which calls GIAnT package for 
#  timeseries analysis. 
#
# INPUT:
#  step: prepxml_SBAS, PrepIgramStack, ProcessStack, SBASInvert
# OUTPUT:
#
# EXAMPLES:
#  

#######################################################

function prepxml_SBAS(){
  bold "Changing directory to:"
  mkdir -p ${runFolder}/giant  #${giantFolder}
  echo ${runFolder}/giant
  cd ${runFolder}/giant
  openInIpython "${ADOREFOLDER}/lib/python/giant/prepxml_SBAS.py"    
}

function prepxml_MINTS(){
  bold "Changing directory to:"
  mkdir -p ${runFolder}/giant  #${giantFolder}
  echo ${runFolder}/giant
  cd ${runFolder}/giant
  openInIpython "${ADOREFOLDER}/lib/python/giant/prepxml_MINTS.py"    
}

function PrepIgramStack(){
  bold "Changing directory to:"
  mkdir -p ${runFolder}/giant  #${giantFolder}
  echo ${runFolder}/giant
  cd ${runFolder}/giant
  ls ${i12sFolder}/*/coarseorb.drs > ifg.list
  PrepIgramStack.py -u ${GIANT}/SCR/userfn_adore.py -i ifg.list ${@} 
}

function ProcessStack(){
  ProcessStack.py ${@}
}

function SBASInvert(){
  SBASInvert.py ${@}
}

function giant_default(){
  local cmd=${1}
  shift
  eval "${cmd}.py ${@}"
}

function giant_list(){
cat << _EOF
Available GIAnT commands:

prepxml_SBAS   PrepIgramStack  SBASInvert    DatatoWavelet              plotts
prepxml_MINTS  ProcessStack    NSBASInvert   InvertWaveletCoeffs        make_movie
                               TimefnInvert  InvertWaveletCoeffs_folds  make_kml
                                             WavelettoData               
                               SBASxval      InvertWaveletCoeffs_xval
                               Timefnxval    WavelettoData_xval
_EOF

}

#####################
## MAIN ##
#####################
case ${1} in
  "*;*")
    for gp in `echo ${1}|tr ";" " "`
    do
      giant "${gp}"
    done
  ;;
  "prepxml_SBAS")
    shift
    prepxml_SBAS
  ;;
  "PrepIgramStack")
    shift
    PrepIgramStack ${@}
  ;;
  "ProcessStack")
    shift
    ProcessStack ${@}
  ;;
  "SBASInvert")
    shift
    SBASInvert ${@}
  ;;
  "list")
    shift
    giant_list
  ;;
  "prepxml_MINTS")
    shift
    prepxml_MINTS
  ;;
  *)
    giant_default ${@}
  ;;
esac

